package com.bm.console.pojo;

import com.alibaba.fastjson.JSON;
import com.sys.object.common.page.Page;
import lombok.Data;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class WebHouse extends Page implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 房源ID
     */
    private Long id;
    /**
     * 标题
     */
    private String title;

    private String type;
    /**
     * 国家ID
     */
    private Long countryId;
    /**
     * 州ID
     */
    private Long stateId;
    /**
     * 城市Id
     */
    private Long cityId;
    /**
     * 邮编
     */
    private String postCode;
    /**
     * 地址
     */
    private String address;
    /**
     * 图片
     */
    private String photo;
    /**
     * 纬度
     */
    private Double latitude;
    /**
     * 经度
     */
    private Double longitude;
    /**
     * 交房日期
     */
    private String handoverDate;
    /**
     * 项目类型ID
     */
    private Long projectTypeId;
    /**
     * 价格段ID
     */
    private Long priceSectionId;
    /**
     * 价格
     */
    private Double price;
    /**
     * 最小价格
     */
    private Double minPrice;
    /**
     * 最大价格
     */
    private Double maxPrice;
    /**
     * 面积
     */
    private Double area;
    /**
     * 最小面积
     */
    private Double minArea;
    /**
     * 最大面积
     */
    private Double maxArea;
    /**
     * 最近一年房价涨幅
     */
    private Double rose;
    /**
     * 年均租金收益
     */
    private Double rent;
    /**
     * 首付比例
     */
    private Double downPayment;
    /**
     * 房屋产权
     */
    private String housingProperty;
    /**
     * 标签
     */
    private String tags;
    /**
     * 状态，1热卖,2在售,3售罄,4稀缺,5特惠,6尾盘
     */
    private Integer status;
    /**
     * 是否展示
     */
    private Boolean isShow;
    /**
     * 是否删除
     */
    private Boolean isDelete;
    /**
     * 是否推荐
     */
    private Boolean isRecommend;
    /**
     * 是否置顶
     */
    private Boolean isTop;
    /**
     * 项目特色
     */
    private String feature;
    /**
     * 交通情况
     */
    private String traffic;
    /**
     * 项目配套
     */
    private String mating;
    /**
     * schoolDistrict
     */
    private String schoolDistrict;
    /**
     * 视频
     */
    private String video;
    /**
     * 户型介绍
     */
    private String description;
    /**
     * 浏览量
     */
    private Integer pageView;
    /**
     * 虚拟浏览量
     */
    private Integer virtualPageView;
    /**
     * createTime
     */
    private Date createTime;
    /**
     * createId
     */
    private Integer createId;
    /**
     * updateId
     */
    private Integer updateId;
    /**
     * updateTime
     */
    private Date updateTime;
    /**
     * seoTitle
     */
    private String seoTitle;
    /**
     * seoKeyword
     */
    private String seoKeyword;
    /**
     * seoDescription
     */
    private String seoDescription;
    /**
     * 排序
     */
    private Integer sort;

    private String investmentTypeIds;

    private String houseTypeIds;

    private String filedata;

    private String fileext;

    private String photos;

    private String basePhotos;

    private String images;

    private Double propertyTax; //房产税

    private Double propertyFee; //物业费

    private Double apr;  //年利率

    public String getPhotos() {

        System.err.println("====================base64Photos  get======================"+images+"==");
        if (!org.springframework.util.StringUtils.isEmpty(images)) {
            List<String> list = new ArrayList<>();
            StringBuffer buf = new StringBuffer();
            String[] imgs = images.split(",");
            for (String image : imgs) {
                buf.append(image);
                list.add(buf.toString());
                buf.delete(0, buf.length());
                System.err.println("image:" + image);
            }
            this.photos = Base64.encodeBase64String(JSON.toJSONString(list).getBytes());

            System.err.println(basePhotos);
        }

        return photos;
    }

    public String getBasePhotos() {

        System.err.println("====================base64Photos  get======================"+images+"==");
        if (!org.springframework.util.StringUtils.isEmpty(images)) {
            List<String> list = new ArrayList<>();
            StringBuffer buf = new StringBuffer();
            String[] imgs = images.split(",");
            for (String image : imgs) {
                buf.append(DigestUtils.md5Hex(image)).append("###").append(image);
                list.add(buf.toString());
                buf.delete(0, buf.length());
                System.err.println("image:" + image);
            }
            this.basePhotos = Base64.encodeBase64String(JSON.toJSONString(list).getBytes());

            System.err.println(basePhotos);
        }
        return basePhotos;
    }
}